const MapValues = require('../template')

console.log("=== MapValues 复杂场景测试 ===")

// 测试多层循环引用映射值
console.log(
  "多层循环引用映射值:", (() => {
    const obj1 = { id: 1, name: 'obj1' }
    const obj2 = { id: 2, name: 'obj2' }
    const obj3 = { id: 3, name: 'obj3' }

    obj1.ref = obj2
    obj2.ref = obj3
    obj3.ref = obj1

    const mapped = MapValues.mapValues(obj1, value => {
      if (typeof value === 'object' && value !== null) {
        return { ...value, processed: true }
      }
      return value * 2
    })

    return typeof mapped === 'object' &&
      mapped.id === 2 &&
      mapped.name === 'obj1' &&
      typeof mapped.ref === 'object' &&
      mapped.ref.id === 2 &&
      mapped.ref.name === 'obj2' &&
      mapped.ref.processed === true &&
      typeof mapped.ref.ref === 'object' &&
      mapped.ref.ref.id === 3 &&
      mapped.ref.ref.name === 'obj3' &&
      mapped.ref.ref.processed === true &&
      typeof mapped.ref.ref.ref === 'object' &&
      mapped.ref.ref.ref.id === 1 &&
      mapped.ref.ref.ref.name === 'obj1' &&
      mapped.ref.ref.ref.processed === true
  })()
)

// 测试混合类型复杂结构映射值
console.log(
  "混合类型复杂结构映射值:", (() => {
    const obj = {
      string: 'test',
      number: 42,
      boolean: true,
      null: null,
      undefined: undefined,
      array: [1, 'two', { three: 3 }],
      object: { nested: { deep: 'value' } },
      date: new Date('2023-01-01'),
      regex: /test/gi,
      function: function test() { return 'hello' },
      symbol: Symbol('test'),
      bigint: BigInt(123),
      map: new Map([['a', 1], ['b', 2]]),
      set: new Set([1, 2, 3]),
      typedArray: new Uint8Array([1, 2, 3]),
      arrayBuffer: new ArrayBuffer(8),
      dataView: new DataView(new ArrayBuffer(8)),
      error: new Error('test error')
    }

    const mapped = MapValues.mapValues(obj, value => {
      if (typeof value === 'string') return value.toUpperCase()
      if (typeof value === 'number') return value * 2
      if (typeof value === 'boolean') return !value
      if (value === null) return 'null'
      if (value === undefined) return 'undefined'
      if (Array.isArray(value)) return value.map(x => x)
      if (typeof value === 'object' && value !== null) return { ...value, processed: true }
      if (typeof value === 'function') return value
      if (typeof value === 'symbol') return value
      if (typeof value === 'bigint') return value * BigInt(2)
      if (value instanceof Map) return new Map([...value.entries()])
      if (value instanceof Set) return new Set([...value])
      if (value instanceof Uint8Array) return new Uint8Array([...value])
      if (value instanceof ArrayBuffer) return value
      if (value instanceof DataView) return value
      if (value instanceof Error) return new Error(value.message)
      if (value instanceof Date) return new Date(value.getTime())
      if (value instanceof RegExp) return new RegExp(value.source, value.flags)
      return value
    })

    return typeof mapped === 'object' &&
      mapped.string === 'TEST' &&
      mapped.number === 84 &&
      mapped.boolean === false &&
      mapped.null === 'null' &&
      mapped.undefined === 'undefined' &&
      Array.isArray(mapped.array) &&
      mapped.array[0] === 1 &&
      mapped.array[1] === 'two' &&
      typeof mapped.array[2] === 'object' &&
      mapped.array[2].three === 3 &&
      typeof mapped.object === 'object' &&
      mapped.object.processed === true &&
      typeof mapped.object.nested === 'object' &&
      mapped.object.nested.processed === true &&
      mapped.object.nested.deep === 'value' &&
      mapped.date instanceof Date &&
      mapped.date.getTime() === obj.date.getTime() &&
      mapped.regex instanceof RegExp &&
      mapped.regex.source === obj.regex.source &&
      mapped.regex.flags === obj.regex.flags &&
      typeof mapped.function === 'function' &&
      mapped.symbol === obj.symbol &&
      mapped.bigint === BigInt(246) &&
      mapped.map instanceof Map &&
      mapped.map.size === obj.map.size &&
      mapped.set instanceof Set &&
      mapped.set.size === obj.set.size &&
      mapped.typedArray instanceof Uint8Array &&
      mapped.typedArray.length === obj.typedArray.length &&
      mapped.arrayBuffer === obj.arrayBuffer &&
      mapped.dataView === obj.dataView &&
      mapped.error instanceof Error &&
      mapped.error.message === obj.error.message &&
      !('string' in mapped) ||
      !('number' in mapped) ||
      !('boolean' in mapped) ||
      !('null' in mapped) ||
      !('undefined' in mapped) ||
      !('array' in mapped) ||
      !('object' in mapped) ||
      !('date' in mapped) ||
      !('regex' in mapped) ||
      !('function' in mapped) ||
      !('symbol' in mapped) ||
      !('bigint' in mapped) ||
      !('map' in mapped) ||
      !('set' in mapped) ||
      !('typedArray' in mapped) ||
      !('arrayBuffer' in mapped) ||
      !('dataView' in mapped) ||
      !('error' in mapped)
  })()
)

// 测试深度嵌套数组映射值
console.log(
  "深度嵌套数组映射值:", (() => {
    let arr = [1, 2, 3]
    for (let i = 0; i < 10; i++) {
      arr = [arr, { level: i, data: `level${i}` }]
    }

    const obj = { arr, data: 'test' }
    const mapped = MapValues.mapValues(obj, value => {
      if (Array.isArray(value)) {
        return value.map(item => {
          if (Array.isArray(item)) {
            return item.map(x => x)
          }
          if (typeof item === 'object' && item !== null) {
            return { ...item, processed: true }
          }
          return item
        })
      }
      if (typeof value === 'string') {
        return value.toUpperCase()
      }
      return value
    })

    return typeof mapped === 'object' &&
      Array.isArray(mapped.arr) &&
      mapped.arr.length === 2 &&
      Array.isArray(mapped.arr[0]) &&
      mapped.arr[0].length === 2 &&
      Array.isArray(mapped.arr[0][0]) &&
      mapped.arr[0][0].length === 2 &&
      Array.isArray(mapped.arr[0][0][0]) &&
      mapped.arr[0][0][0].length === 2 &&
      Array.isArray(mapped.arr[0][0][0][0]) &&
      mapped.arr[0][0][0][0].length === 2 &&
      Array.isArray(mapped.arr[0][0][0][0][0]) &&
      mapped.arr[0][0][0][0][0].length === 2 &&
      Array.isArray(mapped.arr[0][0][0][0][0][0]) &&
      mapped.arr[0][0][0][0][0][0].length === 2 &&
      Array.isArray(mapped.arr[0][0][0][0][0][0][0]) &&
      mapped.arr[0][0][0][0][0][0][0].length === 2 &&
      Array.isArray(mapped.arr[0][0][0][0][0][0][0][0]) &&
      mapped.arr[0][0][0][0][0][0][0][0].length === 2 &&
      Array.isArray(mapped.arr[0][0][0][0][0][0][0][0][0]) &&
      mapped.arr[0][0][0][0][0][0][0][0][0].length === 2 &&
      Array.isArray(mapped.arr[0][0][0][0][0][0][0][0][0][0]) &&
      mapped.arr[0][0][0][0][0][0][0][0][0][0].length === 2 &&
      Array.isArray(mapped.arr[0][0][0][0][0][0][0][0][0][0][0]) &&
      mapped.arr[0][0][0][0][0][0][0][0][0][0][0].length === 3 &&
      mapped.arr[0][0][0][0][0][0][0][0][0][0][0][0] === 1 &&
      mapped.arr[0][0][0][0][0][0][0][0][0][0][0][1] === 2 &&
      mapped.arr[0][0][0][0][0][0][0][0][0][0][0][2] === 3 &&
      typeof mapped.arr[0][0][0][0][0][0][0][0][0][0][1] === 'object' &&
      mapped.arr[0][0][0][0][0][0][0][0][0][0][1].level === 9 &&
      mapped.arr[0][0][0][0][0][0][0][0][0][0][1].data === 'level9' &&
      mapped.arr[0][0][0][0][0][0][0][0][0][0][1].processed === true &&
      typeof mapped.arr[1] === 'object' &&
      mapped.arr[1].level === 10 &&
      mapped.arr[1].data === 'level10' &&
      mapped.arr[1].processed === true &&
      mapped.data === 'TEST'
  })()
)

// 测试原型链继承映射值
console.log(
  "原型链继承映射值:", (() => {
    function BaseClass() {
      this.baseProp = 'base'
    }
    BaseClass.prototype.baseMethod = function() { return 'base method' }

    function DerivedClass() {
      BaseClass.call(this)
      this.derivedProp = 'derived'
    }
    DerivedClass.prototype = Object.create(BaseClass.prototype)
    DerivedClass.prototype.constructor = DerivedClass
    DerivedClass.prototype.derivedMethod = function() { return 'derived method' }

    const instance = new DerivedClass()
    const mapped = MapValues.mapValues(instance, value => {
      if (typeof value === 'string') return value.toUpperCase()
      return value
    })

    return typeof mapped === 'object' &&
      mapped.baseProp === 'BASE' &&
      mapped.derivedProp === 'DERIVED' &&
      !('baseMethod' in mapped) &&
      !('derivedMethod' in mapped)
  })()
)

// 测试自定义类实例映射值
console.log(
  "自定义类实例映射值:", (() => {
    class CustomClass {
      constructor(value) {
        this.value = value
        this.timestamp = new Date()
      }

      getValue() {
        return this.value
      }

      setValue(newValue) {
        this.value = newValue
      }
    }

    const instance = new CustomClass('test')
    const mapped = MapValues.mapValues(instance, value => {
      if (typeof value === 'string') return value.toUpperCase()
      if (value instanceof Date) return new Date(value.getTime())
      return value
    })

    return typeof mapped === 'object' &&
      mapped.value === 'TEST' &&
      mapped.timestamp instanceof Date &&
      mapped.timestamp.getTime() === instance.timestamp.getTime() &&
      !('getValue' in mapped) &&
      !('setValue' in mapped)
  })()
)

// 测试稀疏数组映射值
console.log(
  "稀疏数组映射值:", (() => {
    const arr = new Array(1000)
    arr[0] = 'first'
    arr[999] = 'last'
    arr[500] = 'middle'

    const obj = { arr, data: 'test' }
    const mapped = MapValues.mapValues(obj, value => {
      if (Array.isArray(value)) {
        return value.map(x => x ? x.toUpperCase() : x)
      }
      if (typeof value === 'string') {
        return value.toUpperCase()
      }
      return value
    })

    return typeof mapped === 'object' &&
      Array.isArray(mapped.arr) &&
      mapped.arr.length === 1000 &&
      mapped.arr[0] === 'FIRST' &&
      mapped.arr[500] === 'MIDDLE' &&
      mapped.arr[999] === 'LAST' &&
      mapped.data === 'TEST'
  })()
)

// 测试TypedArray嵌套映射值
console.log(
  "TypedArray嵌套映射值:", (() => {
    const obj = {
      uint8Array: new Uint8Array([1, 2, 3]),
      int16Array: new Int16Array([100, 200, 300]),
      float32Array: new Float32Array([1.1, 2.2, 3.3]),
      nested: {
        uint32Array: new Uint32Array([1000, 2000, 3000]),
        int8Array: new Int8Array([-1, -2, -3])
      }
    }

    const mapped = MapValues.mapValues(obj, value => {
      if (value instanceof Uint8Array) {
        return new Uint8Array([...value].map(x => x * 2))
      }
      if (value instanceof Int16Array) {
        return new Int16Array([...value].map(x => x * 2))
      }
      if (value instanceof Float32Array) {
        return new Float32Array([...value].map(x => x * 2))
      }
      if (value instanceof Uint32Array) {
        return new Uint32Array([...value].map(x => x * 2))
      }
      if (value instanceof Int8Array) {
        return new Int8Array([...value].map(x => x * 2))
      }
      if (typeof value === 'object' && value !== null) {
        return { ...value, processed: true }
      }
      return value
    })

    return typeof mapped === 'object' &&
      mapped.uint8Array instanceof Uint8Array &&
      mapped.uint8Array[0] === 2 &&
      mapped.uint8Array[1] === 4 &&
      mapped.uint8Array[2] === 6 &&
      mapped.int16Array instanceof Int16Array &&
      mapped.int16Array[0] === 200 &&
      mapped.int16Array[1] === 400 &&
      mapped.int16Array[2] === 600 &&
      mapped.float32Array instanceof Float32Array &&
      mapped.float32Array[0] === 2.2 &&
      mapped.float32Array[1] === 4.4 &&
      mapped.float32Array[2] === 6.6 &&
      typeof mapped.nested === 'object' &&
      mapped.nested.processed === true &&
      mapped.nested.uint32Array instanceof Uint32Array &&
      mapped.nested.uint32Array[0] === 2000 &&
      mapped.nested.uint32Array[1] === 4000 &&
      mapped.nested.uint32Array[2] === 6000 &&
      mapped.nested.int8Array instanceof Int8Array &&
      mapped.nested.int8Array[0] === -2 &&
      mapped.nested.int8Array[1] === -4 &&
      mapped.nested.int8Array[2] === -6
  })()
)

// 测试Map和Set嵌套映射值
console.log(
  "Map和Set嵌套映射值:", (() => {
    const map1 = new Map([['a', 1], ['b', 2]])
    const map2 = new Map([['c', 3], ['d', 4]])
    const set1 = new Set([1, 2, 3])
    const set2 = new Set([4, 5, 6])

    const obj = {
      maps: { map1, map2 },
      sets: { set1, set2 },
      nested: {
        map: new Map([['nested', 'value']]),
        set: new Set(['nested'])
      }
    }

    const mapped = MapValues.mapValues(obj, value => {
      if (value instanceof Map) {
        return new Map([...value.entries()].map(([k, v]) => [k, v * 2]))
      }
      if (value instanceof Set) {
        return new Set([...value].map(x => x * 2))
      }
      if (typeof value === 'object' && value !== null) {
        return { ...value, processed: true }
      }
      return value
    })

    return typeof mapped === 'object' &&
      typeof mapped.maps === 'object' &&
      mapped.maps.processed === true &&
      mapped.maps.map1 instanceof Map &&
      mapped.maps.map1.get('a') === 2 &&
      mapped.maps.map1.get('b') === 4 &&
      mapped.maps.map2 instanceof Map &&
      mapped.maps.map2.get('c') === 6 &&
      mapped.maps.map2.get('d') === 8 &&
      typeof mapped.sets === 'object' &&
      mapped.sets.processed === true &&
      mapped.sets.set1 instanceof Set &&
      mapped.sets.set1.has(2) &&
      mapped.sets.set1.has(4) &&
      mapped.sets.set1.has(6) &&
      mapped.sets.set2 instanceof Set &&
      mapped.sets.set2.has(8) &&
      mapped.sets.set2.has(10) &&
      mapped.sets.set2.has(12) &&
      typeof mapped.nested === 'object' &&
      mapped.nested.processed === true &&
      mapped.nested.map instanceof Map &&
      mapped.nested.map.get('nested') === 'value' &&
      mapped.nested.set instanceof Set &&
      mapped.nested.set.has('nested')
  })()
)

// 测试Error对象嵌套映射值
console.log(
  "Error对象嵌套映射值:", (() => {
    const error1 = new Error('First error')
    error1.code = 'ERR_001'
    error1.details = { line: 10, column: 5 }

    const error2 = new TypeError('Second error')
    error2.code = 'ERR_002'
    error2.stack = 'TypeError: Second error\n    at test.js:15:10'

    const obj = {
      errors: [error1, error2],
      nested: {
        error: new ReferenceError('Third error'),
        data: { message: 'test' }
      }
    }

    const mapped = MapValues.mapValues(obj, value => {
      if (Array.isArray(value)) {
        return value.map(item => {
          if (item instanceof Error) {
            return new Error(item.message.toUpperCase())
          }
          return item
        })
      }
      if (value instanceof Error) {
        return new Error(value.message.toUpperCase())
      }
      if (typeof value === 'object' && value !== null) {
        return { ...value, processed: true }
      }
      return value
    })

    return typeof mapped === 'object' &&
      Array.isArray(mapped.errors) &&
      mapped.errors.length === 2 &&
      mapped.errors[0] instanceof Error &&
      mapped.errors[0].message === 'FIRST ERROR' &&
      mapped.errors[1] instanceof Error &&
      mapped.errors[1].message === 'SECOND ERROR' &&
      typeof mapped.nested === 'object' &&
      mapped.nested.processed === true &&
      mapped.nested.error instanceof Error &&
      mapped.nested.error.message === 'THIRD ERROR' &&
      typeof mapped.nested.data === 'object' &&
      mapped.nested.data.processed === true &&
      mapped.nested.data.message === 'test'
  })()
)

// 测试Date对象嵌套映射值
console.log(
  "Date对象嵌套映射值:", (() => {
    const date1 = new Date('2023-01-01')
    const date2 = new Date('2023-12-31')
    const date3 = new Date('2023-06-15')

    const obj = {
      dates: [date1, date2, date3],
      nested: {
        created: date1,
        updated: date2,
        metadata: {
          timestamp: date3,
          data: 'test'
        }
      }
    }

    const mapped = MapValues.mapValues(obj, value => {
      if (Array.isArray(value)) {
        return value.map(item => {
          if (item instanceof Date) {
            return new Date(item.getTime() + 24 * 60 * 60 * 1000) // 加一天
          }
          return item
        })
      }
      if (value instanceof Date) {
        return new Date(value.getTime() + 24 * 60 * 60 * 1000) // 加一天
      }
      if (typeof value === 'object' && value !== null) {
        return { ...value, processed: true }
      }
      return value
    })

    return typeof mapped === 'object' &&
      Array.isArray(mapped.dates) &&
      mapped.dates.length === 3 &&
      mapped.dates[0] instanceof Date &&
      mapped.dates[0].getTime() === date1.getTime() + 24 * 60 * 60 * 1000 &&
      mapped.dates[1] instanceof Date &&
      mapped.dates[1].getTime() === date2.getTime() + 24 * 60 * 60 * 1000 &&
      mapped.dates[2] instanceof Date &&
      mapped.dates[2].getTime() === date3.getTime() + 24 * 60 * 60 * 1000 &&
      typeof mapped.nested === 'object' &&
      mapped.nested.processed === true &&
      mapped.nested.created instanceof Date &&
      mapped.nested.created.getTime() === date1.getTime() + 24 * 60 * 60 * 1000 &&
      mapped.nested.updated instanceof Date &&
      mapped.nested.updated.getTime() === date2.getTime() + 24 * 60 * 60 * 1000 &&
      typeof mapped.nested.metadata === 'object' &&
      mapped.nested.metadata.processed === true &&
      mapped.nested.metadata.timestamp instanceof Date &&
      mapped.nested.metadata.timestamp.getTime() === date3.getTime() + 24 * 60 * 60 * 1000 &&
      mapped.nested.metadata.data === 'test'
  })()
)

// 测试RegExp对象嵌套映射值
console.log(
  "RegExp对象嵌套映射值:", (() => {
    const regex1 = /test/gi
    const regex2 = /pattern/im
    const regex3 = /example/gu

    const obj = {
      patterns: [regex1, regex2, regex3],
      nested: {
        email: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
        phone: /^\+?[\d\s-()]+$/,
        config: {
          url: /^https?:\/\/.+/,
          data: 'test'
        }
      }
    }

    const mapped = MapValues.mapValues(obj, value => {
      if (Array.isArray(value)) {
        return value.map(item => {
          if (item instanceof RegExp) {
            return new RegExp(item.source.toUpperCase(), item.flags)
          }
          return item
        })
      }
      if (value instanceof RegExp) {
        return new RegExp(value.source.toUpperCase(), value.flags)
      }
      if (typeof value === 'object' && value !== null) {
        return { ...value, processed: true }
      }
      return value
    })

    return typeof mapped === 'object' &&
      Array.isArray(mapped.patterns) &&
      mapped.patterns.length === 3 &&
      mapped.patterns[0] instanceof RegExp &&
      mapped.patterns[0].source === 'TEST' &&
      mapped.patterns[0].flags === 'gi' &&
      mapped.patterns[1] instanceof RegExp &&
      mapped.patterns[1].source === 'PATTERN' &&
      mapped.patterns[1].flags === 'im' &&
      mapped.patterns[2] instanceof RegExp &&
      mapped.patterns[2].source === 'EXAMPLE' &&
      mapped.patterns[2].flags === 'gu' &&
      typeof mapped.nested === 'object' &&
      mapped.nested.processed === true &&
      mapped.nested.email instanceof RegExp &&
      mapped.nested.email.source === '^[^\\S@]+@[^\\S@]+\\.[^\\S@]+$' &&
      mapped.nested.phone instanceof RegExp &&
      mapped.nested.phone.source === '^\\+?[\\D\\S-()]+$' &&
      typeof mapped.nested.config === 'object' &&
      mapped.nested.config.processed === true &&
      mapped.nested.config.url instanceof RegExp &&
      mapped.nested.config.url.source === '^HTTPS?:\\/\\/.+' &&
      mapped.nested.config.data === 'test'
  })()
)

// 测试Symbol对象嵌套映射值
console.log(
  "Symbol对象嵌套映射值:", (() => {
    const sym1 = Symbol('test1')
    const sym2 = Symbol('test2')
    const sym3 = Symbol('test3')

    const obj = {
      symbols: [sym1, sym2, sym3],
      nested: {
        key1: sym1,
        key2: sym2,
        config: {
          key3: sym3,
          data: 'test'
        }
      }
    }

    const mapped = MapValues.mapValues(obj, value => {
      if (Array.isArray(value)) {
        return value.map(item => {
          if (typeof item === 'symbol') {
            return Symbol(item.description?.toUpperCase())
          }
          return item
        })
      }
      if (typeof value === 'symbol') {
        return Symbol(value.description?.toUpperCase())
      }
      if (typeof value === 'object' && value !== null) {
        return { ...value, processed: true }
      }
      return value
    })

    return typeof mapped === 'object' &&
      Array.isArray(mapped.symbols) &&
      mapped.symbols.length === 3 &&
      typeof mapped.symbols[0] === 'symbol' &&
      mapped.symbols[0].description === 'TEST1' &&
      typeof mapped.symbols[1] === 'symbol' &&
      mapped.symbols[1].description === 'TEST2' &&
      typeof mapped.symbols[2] === 'symbol' &&
      mapped.symbols[2].description === 'TEST3' &&
      typeof mapped.nested === 'object' &&
      mapped.nested.processed === true &&
      typeof mapped.nested.key1 === 'symbol' &&
      mapped.nested.key1.description === 'TEST1' &&
      typeof mapped.nested.key2 === 'symbol' &&
      mapped.nested.key2.description === 'TEST2' &&
      typeof mapped.nested.config === 'object' &&
      mapped.nested.config.processed === true &&
      typeof mapped.nested.config.key3 === 'symbol' &&
      mapped.nested.config.key3.description === 'TEST3' &&
      mapped.nested.config.data === 'test'
  })()
)

// 测试BigInt对象嵌套映射值
console.log(
  "BigInt对象嵌套映射值:", (() => {
    const big1 = BigInt(123)
    const big2 = BigInt(456)
    const big3 = BigInt(789)

    const obj = {
      bigints: [big1, big2, big3],
      nested: {
        value1: big1,
        value2: big2,
        config: {
          value3: big3,
          data: 'test'
        }
      }
    }

    const mapped = MapValues.mapValues(obj, value => {
      if (Array.isArray(value)) {
        return value.map(item => {
          if (typeof item === 'bigint') {
            return item * BigInt(2)
          }
          return item
        })
      }
      if (typeof value === 'bigint') {
        return value * BigInt(2)
      }
      if (typeof value === 'object' && value !== null) {
        return { ...value, processed: true }
      }
      return value
    })

    return typeof mapped === 'object' &&
      Array.isArray(mapped.bigints) &&
      mapped.bigints.length === 3 &&
      mapped.bigints[0] === BigInt(246) &&
      mapped.bigints[1] === BigInt(912) &&
      mapped.bigints[2] === BigInt(1578) &&
      typeof mapped.nested === 'object' &&
      mapped.nested.processed === true &&
      mapped.nested.value1 === BigInt(246) &&
      mapped.nested.value2 === BigInt(912) &&
      typeof mapped.nested.config === 'object' &&
      mapped.nested.config.processed === true &&
      mapped.nested.config.value3 === BigInt(1578) &&
      mapped.nested.config.data === 'test'
  })()
)

// 测试边界情况映射值
console.log(
  "边界情况映射值:", (() => {
    const obj = { '': 'empty key', ' ': 'space key', 'a': 'normal key' }
    const mapped = MapValues.mapValues(obj, value => value.toUpperCase())

    return typeof mapped === 'object' &&
      mapped[''] === 'EMPTY KEY' &&
      mapped[' '] === 'SPACE KEY' &&
      mapped.a === 'NORMAL KEY'
  })()
)

// 测试特殊字符映射值
console.log(
  "特殊字符映射值:", (() => {
    const obj = { 'key-with-dash': 'value1', 'key.with.dot': 'value2' }
    const mapped = MapValues.mapValues(obj, value => value.toUpperCase())

    return typeof mapped === 'object' &&
      mapped['key-with-dash'] === 'VALUE1' &&
      mapped['key.with.dot'] === 'VALUE2'
  })()
)

// 测试数字键映射值
console.log(
  "数字键映射值:", (() => {
    const obj = { 0: 'zero', 1: 'one', 2: 'two' }
    const mapped = MapValues.mapValues(obj, value => value.toUpperCase())

    return typeof mapped === 'object' &&
      mapped[0] === 'ZERO' &&
      mapped[1] === 'ONE' &&
      mapped[2] === 'TWO'
  })()
)

// 测试布尔值键映射值
console.log(
  "布尔值键映射值:", (() => {
    const obj = { true: 'yes', false: 'no' }
    const mapped = MapValues.mapValues(obj, value => value.toUpperCase())

    return typeof mapped === 'object' &&
      mapped.true === 'YES' &&
      mapped.false === 'NO'
  })()
)

// 测试重复值映射值
console.log(
  "重复值映射值:", (() => {
    const obj = { a: 1, b: 1, c: 2 }
    const mapped = MapValues.mapValues(obj, value => value * 2)

    return typeof mapped === 'object' &&
      mapped.a === 2 &&
      mapped.b === 2 &&
      mapped.c === 4
  })()
)

console.log("=== MapValues 复杂场景测试完成 ===")
